<?php
/* TODO: parametrize this cookie code as the rest of the template. Shouldn't be hardcoded with the values for
 * the specific database test suite
 */
require_once(dirname(__FILE__) . "/databaseTesterTemplateData.php");

$selectTestcaseId = 0;

session_start();

/**** We check if the cookie exists and is valid
 * If that's the case, we will use its value
 * If it exists but is not valid, we reset it
 */
if (isset($_COOKIE['selectedTestcaseId'])) {

    //cookie set but is it valid ? Must be an integer in the range [0;<size of $arFunctions]
    if (is_numeric($_COOKIE['selectedTestcaseId'])) {
        $isCookieValid = true;
        $cookieSelectTestcaseId = (int) $_COOKIE['selectedTestcaseId'];

        if ($cookieSelectTestcaseId >= 0 && $cookieSelectTestcaseId < count($arFunctions)) {
            $selectTestcaseId = $cookieSelectTestcaseId;
        } else {
            $isCookieValid = false;
        }
    } else {
        $isCookieValid = false;
    }

    if (!$isCookieValid) {
        // invalid cookie: we reset the cookie's value for next time
        setcookie("selectedTestcaseId",$selectTestcaseId);
    }
    
}
?>
<!DOCTYPE html>
<html>
    <head>
        <title></title>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<?php
/* Configuring the data to feed to the javascript, plus additional javascript code
 * for the test suite
 * That's the 2 variables you want to change to include the files for your test suite
 */

$fileTestSuiteTemplateFunctions = "scripts/databaseTesterTemplateFunctions.js";
//feed in the data. Change the file path to include the test suite of your choice
$fileTestSuiteTemplateData = dirname(__FILE__) . "/databaseTesterTemplateDataOutputter.php";

/*
 * Including the files
 */
echo "<script>";

require_once($fileTestSuiteTemplateData);

echo "</script>";

echo "<script src='../../scripts/jquery-1.5.2.js'></script>";
echo "<script src='scripts/testerTemplate.js'></script>";

echo "<script src='$fileTestSuiteTemplateFunctions'></script>";
?>        


    </head>
    <body>
        <div>Change selection to trigger request : <select id="listBoxPlaceholder"></select>
        <br/>
        Parameter1 : <input type="text" id="inputParam1" />
        <br/>
        Parameter2 : <input type="text" id="inputParam2" />
        <br/>
        Parameter3 : <input type="text" id="inputParam3" />
        </div>

        <div id="console"></div>

    </body>
</html>
